package cn.openea.perpartner.rule.web.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.rule.web.entity.GenTable;
import cn.openea.perpartner.rule.web.service.IGenTableService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (GenTableList)表控制层
 *
 * @author Weird077
 * @since 2022-10-12 10:18:12
 */
@RestController
@RequestMapping("table")
public class GenTableController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private IGenTableService genTableService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @GetMapping("/list")
    public TableDataInfo selectAll() {
        List<GenTable> list = genTableService.list();
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.genTableService.getById(id));
    }

    /**
     * 保存数据
     * @param genTable 实体对象
     * @return 新增结果
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody GenTable genTable) {
        return success(this.genTableService.saveOrUpdate(genTable));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.genTableService.removeByIds(idList));
    }
}

